capture log close

// Set the directory to your own. Here is an example
cd "~/Dropbox/2018 Coalitions/Documentation/Replication files/"

// Start log. Here is an example
log using aq-analyze-table-dv-coalition, replace text

// program: Stata 12.1
// task:  Make Table 1 and run robustness checks
// project: Kang and Tripp 2018 Perspectives on Politics
// author: Alice J. Kang

version 12.1
clear all
set linesize 80
set more off
* To make the tables, which we then edited in Word, we use outreg.
ssc install outreg

// Bring in data
use KangTrippReplication.dta

// Attention: The data set does not include iwm_cum2, pwingo and
// interactions with those variables.

// To obtain iwm_cum2 and make iwm_cum2, please contact the authors of 
// Hughes et al (2015, International Studies Quarterly).

// Here is the code we used to make iwm_cum2 and the interaction term:

/* 
sort year iwm_cum
gen iwm_temp=iwm_cum
by year: replace iwm_temp=iwm_temp[_n-1] if iwm_temp==.
sort country year
by country: ipolate iwm_temp year if year>=1989, gen(iwm_cum2) epolate 
label variable iwm_cum2 "Global pressure, extrapolated (based on Hughes et al)" 

gen iwm_cum2xbpc=iwm_cum2*lbeijingpc
label variable iwm_cum2xbpc "Interaction: iwm_cum2 x lbeijingpc" 
*/

// #1: Make entry variable noting different independence years
*Late entry: Eritrea in 1993, Namibia in 1990
sort country year
gen enter=1989
by country: replace enter=1993 if country=="Eritrea"
by country: replace enter=1990 if country=="Namibia"
label variable enter "1989 or year of independence if after"

// #2: Make begin variable
* Begin risk at 1989
gen begin=1989

// #3: Set
stset year, id(country) failure(coalition==1) enter (time enter-1) ///
	origin(time begin-1)
	
// #4: Make time variables
rename _t t
gen conft=conf_cat23*t

// #5: Make Table 1

* Exclude three countries that adopted quotas prior to 1995: Eritrea, Tanzania, Uganda

* Complementary log-log: International factors
cloglog _d iwm_cum2 lbeijingpc iwm_cum2xbpc ldacpcle t if groups2!=. & plural_lead!=. ///
	& country!="Eritrea" & country!="Tanzania" & country!="Uganda", cluster(country) 
estat ic 
outreg using Table1.doc, ctitle("", 1) se starlevels(10 5 1 .1) sigsymbols(+,*,**,***) bdec(2) replace

* Complementary log-log: Add domestic factors
cloglog _d iwm_cum2 lbeijingpc iwm_cum2xbpc ldacpcle conf_cat23 polity2 groups2 plural_lead ///
	l2gnipcatlasl musmaj t conft if country!="Eritrea" & country!="Tanzania" ///
	& country!="Uganda", cluster(country)
estat ic
outreg using Table1.doc, ctitle("", 2) se starlevels(10 5 1 .1) sigsymbols(+,*,**,***) bdec(2) merge replace

// #6: Run robustness checks using Table 1, Model 2
* Exclude three countries that adopted quotas prior to 1995: Eritrea, Tanzania, Uganda

* Don't model for time dependence, no interaction with time
cloglog _d iwm_cum2 lbeijingpc iwm_cum2xbpc ldacpcle conf_cat23 polity2 groups2 plural_lead ///
	l2gnipcatlasl musmaj if country!="Eritrea" & country!="Tanzania" ///
	& country!="Uganda", cluster(country)

* Include cubic time, no interaction with time
gen t2=_t*_t
gen t3=_t*_t*_t
cloglog _d iwm_cum2 lbeijingpc iwm_cum2xbpc ldacpcle conf_cat23 polity2 groups2 plural_lead ///
	l2gnipcatlasl musmaj t t2 t3 if country!="Eritrea" & country!="Tanzania" ///
	& country!="Uganda", cluster(country)

* PREG instead of Ethnic Power Relations
cloglog _d iwm_cum2 lbeijingpc iwm_cum2xbpc ldacpcle conf_cat23 polity2 preg90 plural_lead ///
	l2gnipcatlasl musmaj t conft if country!="Eritrea" & country!="Tanzania" ///
	& country!="Uganda", cluster(country)

* WINGO instead of Beijing based variable. Use Hughes et al, which goes through 2008 only.
* Please contact Hughes et al for the variable, pwingo
cloglog _d iwm_cum pwingo pwingoxxiwm ldacpcle conf_cat23 polity2 groups2 plural_lead ///
	l2gnipcatlasl musmaj t conft if country!="Eritrea" & country!="Tanzania" ///
	& country!="Uganda", cluster(country) 

* UNPKO in addition to our postconflict variable
cloglog _d iwm_cum2 lbeijingpc iwm_cum2xbpc ldacpcle unpko conf_cat23 polity2 groups2 plural_lead ///
	l2gnipcatlasl musmaj t conft if country!="Eritrea" & country!="Tanzania" ///
	& country!="Uganda", cluster(country)
	
* Women's rights accords in addition to our postconflict variable: drops
cloglog _d iwm_cum2 lbeijingpc iwm_cum2xbpc ldacpcle gendaccord2 conf_cat23 polity2 groups2 plural_lead ///
	l2gnipcatlasl musmaj t conft if country!="Eritrea" & country!="Tanzania" ///
	& country!="Uganda", cluster(country)
 
* Official state religion instead of Muslim majority. Note there is not much variation here
cloglog _d iwm_cum2 lbeijingpc iwm_cum2xbpc ldacpcle conf_cat23 polity2 groups2 plural_lead ///
	l2gnipcatlasl staterel t conft if country!="Eritrea" & country!="Tanzania" ///
	& country!="Uganda", cluster(country)
	
* Percent Catholic instead of Muslim majority
cloglog _d iwm_cum2 lbeijingpc iwm_cum2xbpc ldacpcle conf_cat23 polity2 groups2 plural_lead ///
	l2gnipcatlasl dccathol t conft if country!="Eritrea" & country!="Tanzania" ///
	& country!="Uganda", cluster(country)
	
* How early a country ratified CEDAW. Missing if not ratified.
cloglog _d cedaw_year iwm_cum2 lbeijingpc iwm_cum2xbpc ldacpcle conf_cat23 polity2 groups2 plural_lead ///
	l2gnipcatlasl musmaj t conft if country!="Eritrea" & country!="Tanzania" ///
	& country!="Uganda", cluster(country)

* Democratic transition
cloglog _d iwm_cum2 lbeijingpc iwm_cum2xbpc ldacpcle conf_cat23 polity2 demtransp groups2 plural_lead ///
	l2gnipcatlasl musmaj t conft if country!="Eritrea" & country!="Tanzania" ///
	& country!="Uganda", cluster(country)

* Women in parliament
cloglog _d iwm_cum2 lbeijingpc iwm_cum2xbpc ldacpcle conf_cat23 polity2 groups2 plural_lead ///
	wparl3 l2gnipcatlasl musmaj t conft if country!="Eritrea" & country!="Tanzania" ///
	& country!="Uganda", cluster(country)
	
* Omit plurality variable
cloglog _d adoptratl iwm_cum2 lbeijingpc iwm_cum2xbpc ldacpcle conf_cat23 polity2 groups2 ///
	l2gnipcatlasl musmaj t conft if country!="Eritrea" & country!="Tanzania" ///
	& country!="Uganda", cluster(country)

* Proportional hazard: add interaction of plural_lead with time
gen pluralt=plural_lead*t
cloglog _d iwm_cum2 lbeijingpc iwm_cum2xbpc ldacpcle conf_cat23 polity2 groups2 plural_lead ///
	l2gnipcatlasl musmaj t conft pluralt if country!="Eritrea" & country!="Tanzania" ///
	& country!="Uganda", cluster(country)

* Logit 
logit _d iwm_cum2 lbeijingpc iwm_cum2xbpc ldacpcle polity2 conf_cat23 groups2 plural_lead ///
	l2gnipcatlasl musmaj t conft if country!="Eritrea" & country!="Tanzania" ///
	& country!="Uganda", cluster(country)
 
* Cox: with and without interaction with time
* Change t back to _t
rename t _t
stcox iwm_cum2 lbeijingpc iwm_cum2xbpc ldacpcle polity2 conf_cat23 groups2 plural_lead ///
	l2gnipcatlasl musmaj if country!="Eritrea" & country!="Tanzania" ///
	& country!="Uganda", cluster(country)

stcox iwm_cum2 lbeijingpc iwm_cum2xbpc ldacpcle polity2 conf_cat23 groups2 plural_lead ///
	l2gnipcatlasl musmaj conft if country!="Eritrea" & country!="Tanzania" ///
	& country!="Uganda", cluster(country)
	
* Weibull
streg iwm_cum2 lbeijingpc iwm_cum2xbpc ldacpcle polity2 conf_cat23 groups2 plural_lead ///
	l2gnipcatlasl musmaj if country!="Eritrea" & country!="Tanzania" ///
	& country!="Uganda", cluster(country) d(weib)
	
log close
exit 
